import { Component, OnInit } from '@angular/core';
import {s} from "@angular/core/src/render3";

let numList: number[] = [1,2,3];
let list: Array<number> = [1, 2, 3];
enum Color {
  Red = 1, Green = 2, Blue = 4
}
let matrix: number[][] = [[1,2], [3,4]];
console.log(matrix);
let colorName: string = Color[2];
let c: Color = Color.Green;
console.log(c);
console.log(colorName);
function f(shouldInitialize: boolean) {
  let x = 10;
  if (shouldInitialize) {

    if(true) {
      let x = 20;
      console.log(x);
    }
  }

  return x;
}
let o = {
  a: "foo",
  b: 12,
  c: "bar"
}
let {a, b} = o;
console.log(`${a},${b}`);
type C = {a: string, b?: number};
function f1({a, b} = C) {
  console.log(`${a},${b}`);
}
f1({'aa': 1})
console.log(f(true));  // returns '10'
f(false); // returns 'undefined'

//interface
interface LabelledObj {
  label: string
}
function printLabel(labelledObj: LabelledObj) {
  console.log(labelledObj.label);
}
// printLabel({size: 10, label: 'aa'});

interface ClockInterface {
  currentTime: Date;
}
class Clock implements ClockInterface {
  currentTime: Date;
  constructor(h: number, m: number) {
  }
}
let clock = new Clock(1,1);


//class extends
class Animal {
  constructor(public name: string) { }
}

class Rhino extends Animal {
  age:number;
  constructor(name) { super(name);
    this.age = 10;
  }
}

class Employee {
  private name: string;
  constructor(theName: string) { this.name = theName; }
}

let animal = new Animal("Goat");
let rhino = new Rhino('Rhino');
console.log("rhino name:" + rhino.name);
let employee = new Employee("Bob");
console.log(rhino);
animal = rhino;
console.log(animal)


//getter and setter
let passcode = "secret passcode";
class Employer {
  private __name: string;
  get name(): string{
    console.log("get name");
    return this.__name;
  }
  set name(newname: string) {
    console.log("set name")
    if(passcode === "secret passcode") {
      this.__name = newname;
    }else {
      console.log("wrong code")
    }
  }
}
let employer = new Employer();
employer.name = "zhangzy";
console.log(employer.name)

//static property
class Grid {
  static origin = {x: 0, y: 0};
  calculateDistanceFromOrigin(point: {x: number; y: number;}) {
    let xDist = (point.x - Grid.origin.x);
    let yDist = (point.y - Grid.origin.y);
    return Math.sqrt(xDist * xDist + yDist * yDist) / this.scale;
  }
  constructor (public scale: number) { }
}

let grid1 = new Grid(1.0);  // 1x scale
let grid2 = new Grid(5.0);  // 5x scale

console.log(grid1.calculateDistanceFromOrigin({x: 10, y: 10}));
console.log(grid2.calculateDistanceFromOrigin({x: 10, y: 10}));
console.log(Grid.origin);
Grid.origin = {x: 1, y: 2}
console.log(Grid.origin);
console.log(grid1.calculateDistanceFromOrigin({x: 10, y: 10}));
console.log(grid2.calculateDistanceFromOrigin({x: 10, y: 10}));


class Thing {
  constructor(public distance: number) {
  }
  printDis() {
    console.log(this.distance);
  }
}
class Subthing extends Thing {
  constructor(public dis: number) {
    super(dis);
  }
}
let sub = new Subthing(20);
sub.printDis();
@Component({
  selector: 'app-heroes',
  templateUrl: './heroes.component.html',
  styleUrls: ['./heroes.component.less']
})
export class HeroesComponent implements OnInit {

  constructor() { }

  ngOnInit() {
    const hero = "Windstorm";
  }
  fun():void {

  }

}
